package com.m3839.sdk.login.bean;

import com.m3839.sdk.common.core.Constant;
import com.m3839.sdk.common.core.SdkConfiguration;

import org.json.JSONObject;

/**
 * Description:快爆SDK初始化的相关配置数据
 *
 * @author 陈宝阳
 * @create 2020/8/10 10:23
 */
public class GameConfig {

  /** 正常的游戏数据 */
  private static final String HYKB_KEY_RESPONSE_GAME_NAME = "gameName";
  private static final String HYKB_KEY_RESPONSE_GAME_ICON = "gameIcon";
  /** 维护 */
  private static final String HYKB_KEY_RESPONSE_START_TIME = "maintenanceStartTime";
  private static final String HYKB_KEY_RESPONSE_END_TIME = "maintenanceEndTime";
  private static final String HYKB_KEY_RESPONSE_MAINTENANCE_CONTENT = "maintenanceContent";

  private static final String HYKB_KEY_RESPONSE_VALIDITY = "validity";

  public static final String HYKB_KEY_RESPONSE_CLOSE = "close";
  public static final String HYKB_KEY_RESPONSE_CONTENT = "content";
  public static final String HYKB_KEY_RESPONSE_TIPS = "tips";

  /** 游戏名 */
  private String gameName;
  /** 游戏图标 */
  private String gameIcon;

  /** 维护开始时间 */
  private String startTime;
  /** 维护结束时间 */
  private String endTime;
  /** 维护的公告 */
  private String maintainContent;
  /** 用户信息的有效期 */
  private int validity;

  /**
   * json解析
   * @param dataJson
   * @param code
   * @return
   */
  public static GameConfig parseJson(JSONObject dataJson, int code) {

    GameConfig config = new GameConfig();

    if(code == Constant.HYKB_CODE_SUCCESS) {
      config.gameName = dataJson.optString(HYKB_KEY_RESPONSE_GAME_NAME);
      config.gameIcon = dataJson.optString(HYKB_KEY_RESPONSE_GAME_ICON);
      config.validity = dataJson.optInt(HYKB_KEY_RESPONSE_VALIDITY);
      JSONObject closeObject = dataJson.optJSONObject(HYKB_KEY_RESPONSE_CLOSE);
      if(closeObject != null) {
        SdkConfiguration.setNetErrorContent(closeObject.optString(HYKB_KEY_RESPONSE_CONTENT));
        SdkConfiguration.setNetErrorTips(closeObject.optString(HYKB_KEY_RESPONSE_TIPS));
      }
    }else if(code == Constant.HYKB_CODE_GAME_MAINTENANCE){
      config.startTime = dataJson.optString(HYKB_KEY_RESPONSE_START_TIME);
      config.endTime = dataJson.optString(HYKB_KEY_RESPONSE_END_TIME);
      config.maintainContent = dataJson.optString(HYKB_KEY_RESPONSE_MAINTENANCE_CONTENT);
    }

    return config;
  }

  public String getGameName() {
    return gameName;
  }

  public String getGameIcon() {
    return gameIcon;
  }

  public String getStartTime() {
    return startTime;
  }

  public String getEndTime() {
    return endTime;
  }

  public String getMaintainContent() {
    return maintainContent;
  }

  public int getValidity() {
    return validity;
  }
}
